import scrapy
from scrapy.pipelines.images import ImagesPipeline
from scrapy.exceptions import DropItem


class ImgtestPipeline(ImagesPipeline):

    def get_media_requests(self, item, info):
        img_src = item['img_src']
        yield scrapy.Request(img_src)

    def item_completed(self, results, item, info):
        image_paths = [x['path'] for ok, x in results if ok]
        if not image_paths:
            raise DropItem("该Item没有图片")
        return item